function fig_eigs

close all

k = 2e-1;

addpath ../

p = params;

% compute A(t) numerically
lin_soln = stab(k, p);

t = lin_soln.x;
A = max(abs(lin_soln.y));
% dA = diff(log(A)) ./ diff(t);

[c, dcdt] = deval(lin_soln, lin_soln.x, p.N);
dA = dcdt ./ c;


% computing s(t)
b_soln = base(p);
t2 = b_soln.x;
h0 = b_soln.y(p.N+1,:);

k_star = k * h0;
Ma_star = (h0 - 1 + p.beta) / p.beta * p.Ma;

for i = 1:length(k_star);
    
    p.Ma = Ma_star(i);
    s(i) = comp_eigs(k_star(i), p, h0(i)) ./ h0(i)^2;
    
end

[t_ms, alpha_ms, A_ms] = time_eigs(k, p);

tt = linspace(t(1), t(end), 30);

s = interp1(t2, s, tt);

alpha_ms = interp1(t_ms, alpha_ms, tt);
A_ms = interp1(t_ms, A_ms, tt);


figure
plot(t, A, 'k','linewidth',1);
hold on;
plot(tt, exp(s(1) * tt), 'b--','linewidth',1);
xlabel('$t$','interpreter','latex','fontsize',12);
ylabel('$\tilde{c}(h(t),t)$','interpreter','latex','fontsize',12);
l = legend('numerical','$\exp\left(\sigma(T_0) t\right) $');
set(l,'interpreter','latex','fontsize',12, 'location','northeast');
ylim([0 8]);

figure
plot(t, dA, 'k', tt, s(1) * ones(size(tt)), 'b--', 'linewidth',1);
hold on;
plot(tt, s, 'r*');
ylim([-0.1 0.1]);
xlabel('$t$','interpreter','latex','fontsize',12);
ylabel('Growth rate','interpreter','latex','fontsize',12);
l = legend('numerical','$\sigma(T_0)$','$\sigma(t)$');
set(l,'interpreter','latex','fontsize',12, 'location','southwest');


figure
plot(t, A, 'k', tt, exp(s(1) * tt), 'b--', 'linewidth',1);
hold on;
plot(tt, exp(cumtrapz(tt, s)), 'r*');
% plot(tt, -A_ms, 'r*');
ylim([0 8]);
xlabel('$t$','interpreter','latex','fontsize',12);
ylabel('$\tilde{c}(h(t),t)$','interpreter','latex','fontsize',12);
l = legend('numerical','$\exp\left(\sigma(T_0) t\right) $', '$\exp\left(\int_{0}^{t} \sigma(T)\, \mathrm{d} T\right)$');
set(l,'interpreter','latex','fontsize',12, 'location','northeast');



% subplot(2,1,2)
% plot(t, A, 'k','linewidth',1);
% hold on;
% plot(tt, exp(cumtrapz(tt, s)), 'r*');
% xlabel('$t$','interpreter','latex','fontsize',12);
% ylabel('$\tilde{c}(h(t),t)$','interpreter','latex','fontsize',12);
% l = legend('numerical','$\exp\left(\int_{0}^{t} \sigma(T)\, \mathrm{d} T\right)$');
% set(l,'interpreter','latex','fontsize',12, 'location','northeast');
% 
% subplot(2,1,1);
% plot(t, dA, 'k','linewidth',1);
% hold on;
% plot(tt, s, 'r*');
% ylim([-0.1 0.1]);
% xlabel('$t$','interpreter','latex','fontsize',12);
% ylabel('Growth rate','interpreter','latex','fontsize',12);
% l = legend('numerical','$\sigma(t)$');
% set(l,'interpreter','latex','fontsize',12, 'location','northeast');

% figure
% subplot(2,1,1);
% plot(t, A, 'k', t2, exp(cumtrapz(t2, s)), 'k--','linewidth',1);
% hold on;
% plot(tt, A_ms, 'r*');
% xlabel('$t$','interpreter','latex','fontsize',12);
% ylabel('$\tilde{c}(h(t),t)$','interpreter','latex','fontsize',12);
% l = legend('numerical','frozen-mode','two-timing');
% set(l,'interpreter','latex','fontsize',12, 'location','northeast');
% 
% subplot(2,1,2);
% plot(t, dA, 'k', t2, s, 'k--','linewidth',1);
% hold on
% plot(tt, alpha_ms, 'r*');
% ylim([-0.1 0.1]);
% xlabel('$t$','interpreter','latex','fontsize',12);
% ylabel('Growth rate','interpreter','latex','fontsize',12);
% l = legend('numerical','frozen-mode','two-timing');
set(l,'interpreter','latex','fontsize',12, 'location','northeast');